package com.liyuan.yiqixing.dao;

import com.liyuan.yiqixing.model.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface CommentDao {
    @Insert("Insert into comment(targetId,userComment,modifiedAt,content,type,userCommented)values(#{targetId},#{userComment.id},#{modifiedAt},#{content},#{type},#{userCommented.id})")
    void insertComment(Comment comment);

    @Select("select LAST_INSERT_ID()")
    Integer selectLastInsertId();

    @Select("select * from comment where type =#{type} and targetId = #{targetId} order by id desc")
    Comment[] selectCommentsByTypeAndTargetId(@Param("type") Integer type, Integer targetId);

    @Select("select id,targetId,userComment,modifiedAt,likeCount,left(content,30) as content,isRead,type,userCommented from comment where userCommented = #{userCommented}")
    Comment[] selectCommentsByUserCommentedId(@Param("userCommented") Integer userCommented);

    @Select("select left(content,10) from comment where id = #{targetId}")
    String selectContent(@Param("targetId") Integer targetId);

    @Select("select targetId from comment where id = #{id}")
    Integer selectCommentTargetIdById(@Param("id") Integer targetId);
}
